home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / proxy11.zip / EMAIL.PRX < prev    next >
Text File  |  1991-10-23  |  2KB  |  61 lines

  1.  
  2. // state components
  3.  
  4. //  up = map(string,string)
  5. //  uq = map(string,queue)
  6. //  so = set(string)
  7.  
  8. class queue(procd,remdr) {
  9.  read(;x) {
  10.       if(len remdr==0) return "empty queue";
  11.       x=hd remdr;
  12.       remdr=tl remdr;
  13.       procd=procd conc [x];
  14.       return x;}
  15.  write(msg) {remdr=remdr conc [msg];}
  16.  reset() {remdr=procd conc remdr;
  17.       procd=[];}
  18.  delete() {if(len procd==0) return "empty queue";
  19.        procd=butlast procd;} };
  20.  
  21. up={"super" -> "super"};           // initialize super user with pw "super"
  22. uq={"super" -> new queue([],[])};  // initialize mail-queue for super user
  23.                     // can send mail to him
  24. struct mail {sender,text;};
  25.  
  26. add(u,n,pw) {if (u != "super") return {"not authorized",u};
  27.          uq[n]=new queue([],[]); // initializes mail-queue
  28.          up[n]=pw;             // initializes password
  29.          return "ok";};
  30. drop(u,n) {if (u != "super") return {"not authorized",u};
  31.        if (n notin dom up) return {"unknown user",n};
  32.        up=up ds {n};        // remove user and password
  33.        uq=uq ds {n};        // remove user and mail-queue
  34.        if(n in so) so=so diff {n};    // if user signed on, sign
  35.        return "ok";};                // him off
  36. signon(u,pw) {if (u notin dom up) return {"unknown user", u};
  37.          if (up[u,""] != pw) return "incorrect password";
  38.           so=so U {u};        // sign him on
  39.           return "ok";};
  40. signoff(u) {if (u notin so) return {"not signed on",u};
  41.         so=so diff {u};        // sign him off
  42.         return "ok";};
  43. send(u,t,r;x) { if (u notin so) return {"not signed on",u};
  44.          if (r notin dom up) return {"unknown user",r};
  45.          x=uq[r];
  46.          x.write(new mail(u,t));      // create mail and send
  47.          return "ok";};
  48. read(u;x) {if (u notin so) return {"not signed on",u};
  49.         x=uq[u];
  50.      return x.read;};         // read mail
  51. reset(u;x) {if (u notin so) return {"not signed on",u};
  52.          x=uq[u];
  53.       x.reset;             // reset mail-queue
  54.       return "ok";};
  55. delete(u;x) {if (u notin so) return {"not signed on",u};
  56.           x=uq[u];
  57.        x.delete;             // delete mail
  58.        return "ok";};
  59. so= {};
  60. end
  61.